package com.newtouch.bxzs.database.controller;

import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import com.newtouch.bxzs.database.config.MyLog;
import com.newtouch.bxzs.database.model.*;
import com.newtouch.bxzs.database.service.OrganizationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 组织架构controller类
 *银行、保险、映射机构关系
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2020/12/21 11:33</td>
 * <td>linhongxi</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author lhx
 * @version 1.0.0
 * @since 1.0.0
 */
@Api(tags = "组织机构")
@RestController
@SuppressWarnings("unchecked")
@RequestMapping("/organization")
public class OrganizationController {
    /** 静态变量：系统日志 */
    private static final Log logger = LogFactory.getLog(OrganizationController.class);

    @Autowired
    private OrganizationService organizationService;

    @ApiOperation(value = "组织机构列表--实时查询组织机构列表")
    @PostMapping("/getOrganizationList")
    @MyLog(systemFunctionName = "组织机构",systemFunctionUrl = "/organization/getOrganizationList",userOperationType = 4,userOperationSummary = "查询组织机构树形列表")
    public BaseResponse<OrganizationBO> organizationList(@RequestBody OrganizationListVO organizationListVO) {
        logger.info("实时查询组织机构列表");
        return RespGenerator.returnOK(organizationService.getOrganizationList(organizationListVO));
    }

    @ApiOperation(value = "映射机构新增或者修改页面-获取银行机构列表")
    @PostMapping("/getOrganizationListByPage")
    @MyLog(systemFunctionName = "组织机构",systemFunctionUrl = "/organization/getOrganizationListByPage",userOperationType = 4,userOperationSummary = "查询银行机构列表")
    public BaseResponse<OrganizationBO> organizationListByPage(@RequestBody OrganizationVO organizationVO) {
        logger.info("映射机构新增或者修改页面-获取银行机构列表");
        return RespGenerator.returnOK(organizationService.getOrganizationListByPage(organizationVO));
    }

    @ApiOperation(value = "根据机构主键获取银行或者保险机构详情信息")
    @ApiImplicitParam(name = "organizationId",value = "机构ID",required = true)
    @GetMapping("/getOrganizationInfo")
    @MyLog(systemFunctionName = "组织机构",systemFunctionUrl = "/organization/getOrganizationInfo",userOperationType = 4,userOperationSummary = "查询银行或者保险机构详情信息")
    public BaseResponse<OrganizationBO> organizationInfo(@RequestParam(value = "organizationId", required = false) String organizationId) {
        logger.info("根据机构主键查询组织机构详情");
        return RespGenerator.returnOK(organizationService.getOrganizationInfo(organizationId));

    }

    @ApiOperation(value = "映射机构新增或者修改页面-获取对端机构列表")
    @PostMapping("/getInsuranceList")
    @MyLog(systemFunctionName = "组织机构",systemFunctionUrl = "/organization/getInsuranceList",userOperationType = 4,userOperationSummary = "查询保险机构列表")
    public BaseResponse<CooperationCompanyOrganizationBO> insuranceList(@RequestBody CooperationCompanyOrganizationVO cooperationCompanyOrganizationVO) {
        logger.info("映射机构新增或者修改页面-获取保险机构列表");
        return RespGenerator.returnOK(organizationService.insuranceList(cooperationCompanyOrganizationVO));
    }

    @ApiOperation(value = "根据机构编码查询下级对端机构")
    @PostMapping("/getInsuranceListByCode")
    @MyLog(systemFunctionName = "组织机构",systemFunctionUrl = "/organization/getInsuranceListByCode",userOperationType = 4,userOperationSummary = "查询下级保险机构")
    public BaseResponse<CooperationCompanyOrganizationBO> insuranceListByCode(@RequestBody CooperationCompanyOrganizationListVO cooperationCompanyOrganizationListVO) {
        logger.info("根据机构编码查询下级对端机构");
        return RespGenerator.returnOK(organizationService.getCooperationCompanyOrganizationList(cooperationCompanyOrganizationListVO));
    }

    @ApiOperation(value = "根据用户的机构编码查询本级本端机构")
    @PostMapping("/getOrganizationListByCode")
    @MyLog(systemFunctionName = "组织机构",systemFunctionUrl = "/organization/getOrganizationListByCode",userOperationType = 4,userOperationSummary = "查询用户所属机构")
    public BaseResponse<OrganizationBO> organizationListByCode() {
        logger.info("根据用户的机构编码查询本级本端机构");
        return RespGenerator.returnOK(organizationService.getOrganizationListByCode());
    }

}
